<?php

/**
 * 入库
 * @copyright   Copyright (c) 2006 - 2010 DZH 友拓软件友拓通
 * @category    采购
 * @package   Behavior
 * @author     庄敏学
 * @version  2.1,2012-07-22
 */

class InstockPublicBehavior extends Behavior {
	
	public function run(&$params){
		T('LoadContainer')->run($params,'instock');
		if(C('instock.add')==1){
			return ;
		}
		if(ACTION_NAME=='delete'){
			$info	= M('instock_del')->find($params['id']);
			M('LoadContainer')->where('id='.$info['load_container_id'])->setField('real_arrive_date','');
		}else{
			M('LoadContainer')->where('id='.$params['load_container_id'])->setField('real_arrive_date',$params['real_arrive_date']);
		}
	}
	/// 新入库 检验待入库单子是否保存
	protected function insert(&$params){
		if(C('instock.add')==2){ //开启新入库不需验证
			$load_container_id	= intval($params['load_container_id']);
			$count	= M('instock')->where('load_container_id='.$load_container_id)->count();
			if($count>=1){
				throw_json(L('have_instock'));
			}
		}
	}
	/// 删除时检验 是否开过发票
	protected function delete(&$params){
		$count	= M('InvoiceIn')->where('relation_id='.intval($params['id']))->count();
		if($count>=1){
			throw_json(L('been_invoiced'));
		}
	}
	
}